import { verifyAdminCredentials } from "./auth.ts";

async function testLogin() {
  console.log("====== 登录测试工具 ======");
  
  // 测试凭据
  const username = "admin";
  const password = "password123"; 
  
  console.log(`测试用户: ${username}`);
  console.log(`测试密码: ${password}`);
  
  try {
    console.log("\n1. 验证凭据...");
    const authResult = await verifyAdminCredentials(username, password);
    
    console.log("验证结果:", JSON.stringify(authResult, null, 2));
    
    if (authResult.success) {
      console.log("\n✅ 验证成功!");
      console.log("用户ID:", authResult.userId);
      console.log("用户名:", authResult.username);
      console.log("显示名称:", authResult.displayName);
    } else {
      console.log("\n❌ 验证失败!");
      console.log("错误类型:", authResult.errorType);
      
      if (authResult.errorType === 'incorrect_password') {
        console.log("\n⚠️ 密码不正确。请确认更新了正确的密码哈希。");
        console.log("可以运行: deno run -A utils/update_admin_password.ts");
      } else if (authResult.errorType === 'username_not_found') {
        console.log("\n⚠️ 找不到用户名。请确认数据库中存在admin用户。");
        console.log("可以运行: deno run -A utils/init_db.ts");
      }
    }
  } catch (error) {
    console.error("\n❌ 测试过程中出错:", error);
  }
}

// 运行测试
if (import.meta.main) {
  await testLogin();
} 